package com.last.controller;

import com.last.entity.*;
import com.last.service.IMerchantService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/merchant")
public class MerchantController {

    @Autowired
    private IMerchantService iMerchantService;

    @ApiOperation("查询所有用户")
    @PostMapping("/findAll")
    public List<Merchant> findAll(){
        return iMerchantService.list();
    }

    @ApiOperation("条件查询用户+分页")
    @PostMapping("findAllByPage")
    public PageResult<Merchant> findAllByPage(@RequestBody PageDTO<Merchant> pageDTO){
        return iMerchantService.findAllByPage(pageDTO);
    }

    @ApiOperation("保存或更新用户信息")
    @PostMapping("/saveOrUpdate")
    public Result<Merchant> save(@RequestBody Merchant merchant){
        Boolean b = iMerchantService.saveOrUpdate(merchant);
        return new Result(b,b?"保存成功":"保存失败");
    }

    @ApiOperation("删除单个用户信息")
    @PostMapping("/del")
    public Result<Merchant> del(Integer id){

        Boolean b = iMerchantService.removeById(id);
        return new Result<>(b,b?"删除数据成功":"删除数据失败");
    }
    @ApiOperation("删除多个用户信息")
    @PostMapping("/delByIds")
    public Result<Merchant> delByIds(@RequestBody List<String> ids){
        Boolean b = iMerchantService.removeByIds(ids);
        return new Result(b,b?"删除数据成功":"删除数据失败");
    }
    @ApiOperation("恢复or注销用户信息")
    @PostMapping("/resumeOrCancel")
    public Result<Merchant> resumeOrCancel(@RequestBody Merchant Merchant ){
        return iMerchantService.resumeOrCancel(Merchant);
    }
}
